package adv9;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MyServer {
	public static void main(String[] args) {
		try {
			ServerSocket st = new ServerSocket(6666);
			System.out.println("服务启动了");
			while (true) {
				try {
					Socket s = st.accept();
					System.out.println(s + "链接了。。。");
					InputStream in = s.getInputStream();
					OutputStream out = s.getOutputStream();
					System.out.println(in.getClass().getName());
					System.out.println(out.getClass().getName());
					BufferedReader br = new BufferedReader(
							new InputStreamReader(in));
					String str = null;
					while ((str = br.readLine()) != null) {
						System.out.println(str);
						if (str.length() == 0)
							break;
					}
				} catch (Exception e) {
					System.out.println("有异常！");
				}
			}
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

	}
}
